package org.vectrics.mail.struts;

import org.apache.log4j.Logger;
import org.vectrics.SystemException;
import org.vectrics.common.util.StringUtils;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.struts.Request;

public class GetRequestTemplateParameterLoader {
	private Logger log = Logger.getLogger(this.getClass());

	public GetRequestTemplateParameterLoader() {
		super();
	}

	public TemplateParameterLoader load(Request request) {
		String code = request.getParameter("templateParameterLoader");
		if (StringUtils.isNullOrBlank(code)) { 
			code = "template.loader.default";
			log.info("Using default template loader, because parameter 'templateParameterLoader' not specified in HTTP request");
		}
		TemplateParameterLoader loader = (TemplateParameterLoader)CoreServiceLocator.findServiceBean(code);
		if (loader == null)
			throw new SystemException("Could not find Spring instance for code: " + code);
		log.info("TemplateParameterLoader: " + loader.getClass().getName());
		return(loader);
	}
	
}
